package com.lanchetech.dao;

import com.lanchetech.entity.MerchantPermission;
import com.lanchetech.entity.MerchantRolePermission;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MerchantRolePermissionMapper {
    int insert(MerchantRolePermission record);

    int insertSelective(MerchantRolePermission record);

    int batchInsert(@Param("list") List<MerchantRolePermission> list);

    int deleteByRoleId(@Param("roleId") Long roleId);

    @Select("select p.* from merchant_role_permission a left join merchant_permission p on p.id = a.permission_id where a.role_id = #{id}")
    List<MerchantPermission> getMerchantRolePermissionList(Long id);


    @Insert("<script> insert into merchant_role_permission (role_id,permission_id) values\n" +
            "        <foreach collection=\"list\" item=\"item\" index=\"index\" separator=\",\">\n" +
            "            (#{roleId},#{item})\n" +
            "        </foreach>\n" +
            "</script>"
    )
    void insertMerchantRolePermissions(List<Integer> list, Long roleId);
}